﻿using System;
using AutoMapper;
using Microsoft.Practices.Unity;
using sharp_net;
using sharp_net.Domain;
using sharp_net.Repositories;
using zkdao.Domain;
using zkdao.Repositories.EF;
using zkdao.Email;

namespace zkdao.Application {

    public abstract class BaseApplication {

        protected virtual void DispatchDomainEvent<TEvent>(TEvent evnt)
            where TEvent : IDomainEvent {
            // TODO: Implement the domain event dispatching logic here.
        }

        public static void Initialize() {
            IocLocator.Container.RegisterType<IUserService, UserApplication>();
            IocLocator.Container.RegisterType<IImageService, ImageApplication>();
            IocLocator.Container.RegisterType<IRebateService, RebateApplication>();
            IocLocator.Container.RegisterType<ITagService, TagApplication>();
            IocLocator.Container.RegisterType<IRebateReplyService, RebateReplyApplication>();
            IocLocator.Container.RegisterType<IEmailService, EmailServiceByTX>();
            IocLocator.Container.RegisterType<IRepositoryContext, EFRepositoryContext>();
            IocLocator.Container.RegisterType<IRepository<User>, EntityFrameworkRepository<User>>();
            IocLocator.Container.RegisterType<IRepository<Rebate>, EntityFrameworkRepository<Rebate>>();
            IocLocator.Container.RegisterType<IRepository<RebateReply>, EntityFrameworkRepository<RebateReply>>();
            IocLocator.Container.RegisterType<IRepository<Image>, EntityFrameworkRepository<Image>>();
            IocLocator.Container.RegisterType<IRepository<Tag>, EntityFrameworkRepository<Tag>>();

            Mapper.CreateMap<UserData, User>();
            Mapper.CreateMap<User, UserData>();
            Mapper.CreateMap<Image, ImageData>();
            Mapper.CreateMap<ImageData, Image>();
            Mapper.CreateMap<TagData, Tag>();
            Mapper.CreateMap<Tag, TagData>();
            Mapper.CreateMap<RebateData, Rebate>();
            Mapper.CreateMap<Rebate, RebateData>();
            Mapper.CreateMap<RebateReplyData, RebateReply>();
            Mapper.CreateMap<RebateReply, RebateReplyData>();
            Mapper.CreateMap<RebateReplyData, RebateReply>();
            Mapper.CreateMap<UserRelaRebateData, UserRelaRebate>();
            Mapper.CreateMap<UserRelaRebate, UserRelaRebateData>();
            Mapper.CreateMap<UserRelaRebate, UserRelaRebateData>();
            Mapper.CreateMap<UserRelaRebateData, UserRelaRebate>();
        }
    }
}